import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		market: {},
		userInfo: {},
		recever:{}
	},
	mutations: {
		selectMarket(state, provider){
			state.market = provider;
			console.log('state',state.market)
		},
		login(state, provider) {
			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({ //缓存用户登陆状态
				key: 'userInfo',
				data: provider.userInfo
			})
			console.log('zlcc')
			uni.setStorageSync('token', provider.token);
			uni.setStorageSync('tenantId', provider.userInfo.tenantId);
			uni.setStorageSync('userId', provider.userInfo.id);
			uni.setStorageSync('userInfo', provider.userInfo);
			console.log('login succ userId->', provider.userInfo.id);
		},
		updateUserContent(state, userInfo) {
			let old = state.userInfo
			console.log('old', old)
			old.userInfo = userInfo
			state.userInfo = old;
			console.log('old1', old)
			uni.setStorage({ //缓存用户登陆状态
				key: 'userInfo',
				data: old
			})
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.setStorageSync('token', '')
			// uni.removeStorage({
			// 	key: 'userInfo'
			// })
		},
		checkLogin() {
					let token = uni.getStorageSync('token');
					if (uni.getStorageSync('token') && uni.getStorageSync('userInfo')) {
						return true
					} else {
						return false
					}
				}
	
	},
	actions: {

	}
})

export default store
